<!DOCTYPE html>
<html class="x-admin-sm" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>事由管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!--        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />-->
        <link rel="stylesheet" href="../../static/css/font.css">
        <link rel="stylesheet" href="../../static/css/xadmin.css">
        <script src="../../static/lib/layui/layui.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../static/lib/layui/css/layui.css">
        <script src="../../static/js/jquery.min.js"></script>

        <script type="text/javascript" src="../../static/js/xadmin.js"></script>

        <script type="text/javascript" th:inline="none">
            layui.use('form', function() {
                var form = layui.from;

                // 查询事由
                $.ajax({
                    type: "GET",
                    url: "/matter/findAll",
                    dataType: "json",
                    success: function(data){
                        console.log(data);
                        var u = data.data;
                        //var s = "   <td>" + "<input type='checkbox'/>" + "</td>";
                        for(var i = 0; i < u.length; i++) {
                            console.log("id==>"+u[i].tid);
                            console.log(u[i].cause);
                            console.log(u[i].createDate);
                            var s = "<tr>" +
                               // "   <td>" + u[i].tid + "</td>" +
                                "   <td>" + u[i].cause + "</td>" +
                                "   <td>" + Format(u[i].createDate,'yyyy-MM-dd HH:mm:ss') + "</td>" +
                              /*  "   <td><a title='删除' href=''> " +
                                "     <i class=\"layui-icon\">&#xe640;</i></a></td>"+*/
                                "   <td><a title='删除' onclick='member_del(this,"
                                +u[i].tid+")' href=\"javascript:;\"><i class='layui-icon'>&#xe640;</i></a></td>"+
                            "</tr>";
                            $("#tab").append(s);
                        }
                    }
                });

                function Format(now,mask) {
                    var d = new Date(now);
                    var zeroize = function (value, length)
                    {
                        if (!length) length = 2;
                        value = String(value);
                        for (var i = 0, zeros = ''; i < (length - value.length); i++)
                        {
                            zeros += '0';
                        }
                        return zeros + value;
                    };

                    return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function ($0)
                    {
                        switch ($0)
                        {
                            case 'd': return d.getDate();
                            case 'dd': return zeroize(d.getDate());
                            case 'ddd': return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][d.getDay()];
                            case 'dddd': return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];
                            case 'M': return d.getMonth() + 1;
                            case 'MM': return zeroize(d.getMonth() + 1);
                            case 'MMM': return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
                            case 'MMMM': return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];
                            case 'yy': return String(d.getFullYear()).substr(2);
                            case 'yyyy': return d.getFullYear();
                            case 'h': return d.getHours() % 12 || 12;
                            case 'hh': return zeroize(d.getHours() % 12 || 12);
                            case 'H': return d.getHours();
                            case 'HH': return zeroize(d.getHours());
                            case 'm': return d.getMinutes();
                            case 'mm': return zeroize(d.getMinutes());
                            case 's': return d.getSeconds();
                            case 'ss': return zeroize(d.getSeconds());
                            case 'l': return zeroize(d.getMilliseconds(), 3);
                            case 'L': var m = d.getMilliseconds();
                                if (m > 99) m = Math.round(m / 10);
                                return zeroize(m);
                            case 'tt': return d.getHours() < 12 ? 'am' : 'pm';
                            case 'TT': return d.getHours() < 12 ? 'AM' : 'PM';
                            case 'Z': return d.toUTCString().match(/[A-Z]+$/);
                            // Return quoted strings with the surrounding quotes removed
                            default: return $0.substr(1, $0.length - 2);
                        }
                    });
                };
            });

            function member_del(obj,tid) {
                console.log("tid==",tid);
                layer.confirm('确认要删除吗？', function(index) {
                    //alert(id);
                    $.ajax({
                        type : "DELETE",
                        url : "/matter/del/"+tid,
                        data : {

                        },
                        cache : true,
                        async : true,
                        success: function (data){
                            if(data.code!=20000){
                                layer.msg(data.message);
                            }else{
                                //发异步删除数据
                                $(obj).parents("tr").remove();
                                layer.msg('已删除!', {
                                    icon : 1,
                                    time : 1000
                                });
                            }
                        },
                        error:function () {

                        }

                    });




                });
            }
        </script>

    </head>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="#">首页</a>
                <a href="#">事由管理</a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                                <div class="layui-input-inline layui-show-xs-block">
                                <div class="layui-input-inline layui-show-xs-block">
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">

                                </div>
                                <div class="layui-input-inline layui-show-xs-block">

                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                </div>
                            <div class="layui-input-inline layui-show-xs-block">
                               <!-- <button class="layui-btn" id="searchBtn">
                                    <i class="layui-icon">&#xe615;</i>查询
                                </button>-->
                            </div>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('新增事由','/matter-add',600,192)">
                                <i class="layui-icon"></i>新增</button>
                        </div>
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <table id="tab" class="layui-table layui-form">
                                    <thead>
                                        <tr>
                                            <th>事由</th>
                                            <th>新增日期</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr></tr>
                                    </tbody>
                                </table>
                            </form>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            </div></div>
    </body>
    <script type="text/javascript">

    </script>

</html>
